kernel.bin: build boot16.bin boot32.bin system.bin
	./build


boot16.o: boot16.S
	gcc -c $^ -o $@

boot16.elf: boot16.o
	ld -Ttext=0x0 $^ -o $@

boot16.bin: boot16.elf
	objcopy -O binary $< $@


boot32.o: boot32.S
	gcc -c $^ -o $@

boot32.elf: boot32.o
	ld -Ttext=0x20000 $^ -o $@

boot32.bin: boot32.elf
	objcopy -O binary $< $@


CFLAGS = -std=c11 -I. -fno-pic -mcmodel=kernel -fno-stack-protector -fcf-protection=none

system.elf: head64.o main.o
	ld -Ttext=0xffffffff80100000 $^ -o $@

system.bin: system.elf
	objcopy -O binary $< $@


build: build.c
	gcc $< -o $@

.PHONY: clean run

run: kernel.bin
	~/book/kvmtool/lkvm run -c 1 -k ./kernel.bin

clean:
	rm -rf *.bin *.elf *.o build

